{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 遗传算法主体"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "importing Jupyter notebook from Population.ipynb\n",
      "importing Jupyter notebook from DNA.ipynb\n",
      "importing Jupyter notebook from ScoreAnalyzer.ipynb\n"
     ]
    }
   ],
   "source": [
    "import configure\n",
    "import Population\n",
    "import cProfile"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#一个遗传算法类\n",
    "class ScoreGenerator:\n",
    "\n",
    "    def __init__(self, size, length, rate=0.01, modifiers=[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0]):\n",
    "        if len(modifiers) != 9:\n",
    "            print(\"Modifiers must be exactly 9 elements long.\")\n",
    "            return\n",
    "\n",
    "        self.history = []\n",
    "        self.population = Population.Population(size, length, rate, modifiers)\n",
    "        self.modifiers = modifiers\n",
    "\n",
    "    def generate(self, threshold, deterministic=True):\n",
    "        greatestChild = self.population.getGeneration(self.modifiers, deterministic)\n",
    "        while greatestChild.getFitness(self.modifiers) < threshold:\n",
    "            greatestChild = self.population.getGeneration(self.modifiers, deterministic)\n",
    "        greatestChild.getScore().show('midi')\n",
    "        return greatestChild"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:Empty]",
   "language": "python",
   "name": "conda-env-Empty-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
